package ca.eloas.gpsclock.service;

import android.app.AlarmManager;
import ca.eloas.gpsclock.db.TimeAlarmInfo;

import java.util.Calendar;

/**
 * @author JP
 */
public class TimeAlarm {
    
    private TimeAlarmInfo alarmInfo;

    public TimeAlarm(TimeAlarmInfo alarmInfo) {

        this.alarmInfo = alarmInfo;
    }

    public TimeAlarmInfo getInfo() {
        return alarmInfo;
    }

    public int nextOccurenceInSeconds() {

        Calendar c = Calendar.getInstance();
        int currentTime = c.get(Calendar.HOUR_OF_DAY) * 3600 + c.get(Calendar.MINUTE) * 60 ; // Seconds from midnight;

        int alarmtime = alarmInfo.getHours() * 3600 + alarmInfo.getMinutes() * 60;
        int timetoalarm;
        if ( alarmtime < currentTime ) {

            timetoalarm = (86400 - currentTime) + alarmtime;
        } else {

            timetoalarm = alarmtime - currentTime;
        }
        
        return timetoalarm;
    }

    public void activate(AlarmManager alarmManager) {
        
       // alarmManager.set();
    }
}
